<?php

class ctrl_pdd_pddCat extends L {

    /**
     * 描述 ：PDD产品类目表页面展示
     * 作者 ：Zoro.Zhu
    **/
    public function index(){
        $this->view->_pagingHtml = $this->paging();
        $this->view->headTitle = 'PDD产品类目表';
        $this->display('/html/pdd/pddCat.html');
    }

    /**
     * 描述 : 获取分页
     * 作者 : Zoro.Zhu
     */
    public function &paging($params = array()){
        $sql = model_pddCat::searchSql($params);
        $config = array( 
            '商品类目ID' => array(
                '_attr' => array(
                    'body' => '{`catId`}',
                    'sort' => 'catId'
                )
            ),
            '商品类目名称' => array(
                '_attr' => array(
                    'body' => '{`catName`}',
                    'sort' => 'catName'
                )
            ),
            '父级ID' => array(
                '_attr' => array(
                    'body' => '{`parentId`}',
                    'sort' => 'parentId'
                )
            ),
            '类目等级' => array(
                '_attr' => array(
                    'body' => '{`level`}',
                    'sort' => 'level'
                )
            ),
            '_attr' => array(
                "attr" => array (
                    "table" => 'id=pddCatList class="table table-hover table-condensed table-striped table-scroll jsHoverDetails textC"',
                    "btr" => "align='center' class='of-paging_item_odd tr_{`catId`}'",
                ),
                'data' => &$sql,
                'params' => &$params,
                'call' => array($this, 'asCall'),
                'method' => __METHOD__,
                'save' => 'auto',
                'empty' => '查无此数据'
            )
        );
        return $this->_com->paging($config);
    }

    /**
     * 描述 : 整理数据
     * 作者 : Zoro.Zhu
     */
    public function asCall(&$data){
        foreach($data['data'] as &$val){

        }
    }

    /**
     * 描述 : 新增和修改的页面展示
     * 作者 : Zoro.Zhu
     */
    public function pddCatUpInfo(){
        if(!empty($_REQUEST['catId'])) {
            $pddCat = model_pddCat::getKeyInfo($_REQUEST['catId']);
            if(!empty($pddCat)){ 
                $this->view->catId = $pddCat[0]['catId'];
                $this->view->catName = $pddCat[0]['catName'];
                $this->view->parentId = $pddCat[0]['parentId'];
                $this->view->level = $pddCat[0]['level'];
            }
        }
        $this->display('/html/pdd/pddCatUpInfo.html');
    }

    /**
     * 描述 ：新增或修改数据
     * 作者 ：Zoro.Zhu
    **/
    public function pddCatUpd(){
        //主键为空是新增，否则就是修改
        if(empty($_POST['catId'])){
            $result = model_pddCat::insertSql($_POST);
        }else{
            $result = model_pddCat::updateSql($_POST);
        }
        if($result > 0){
            return array('state' => 200, 'info' => '操作成功');
        }else{
            return array('state' => 301, 'info' => '操作无效');
        }
    }

    /**
     * 描述 ：按条件导出数据
     * 作者 ：Zoro.Zhu
    **/
    public function exportCsv(){
        $sql = model_pddCat::searchSql(array('search' => $_GET));
        $data = L::sql($sql);
        of_base_com_csv::download('导出数据' . time());                     //导出数据的文件名
        of_base_com_csv::download(array('商品类目ID','商品类目名称','父级ID','类目等级',));
        foreach ($data as $row){
            of_base_com_csv::download(array($row['catId'],$row['catName'],$row['parentId'],$row['level'],));
        }
    }

}
return true;